<?php

namespace app\admin\model;

use app\admin\logic\User;
use app\api\controller\Client;
use think\Cache;
use think\Model;

class Order_log extends Model
{
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    protected $insert = ['ip'];
    protected $type = [
        'create_time' => 'timestamp:Y-m-d G:i',//新增时间
    ];

    /**
     * 自动填写ip
     * @return mixed
     */
    protected function setIpAttr()
    {
        return request()->ip();
    }

    /**
     * 新增订单日志
     * @param $data
     */
    public function log($data)
    {
        $this->save($data);
    }

    /**
     * 操作获取器
     * @param $value
     * @param $data
     * @return mixed
     * @author: Huang
     */
    public function getCzactionTextAttr($value, $data)
    {
        $status = [
            1 => "新增订单",
            2 => "修改订单",
            3 => "邀约抢单",
            4 => "门店分单",
            5 => "删除订单",
            6 => "消除异常",
            7 => "反无效申请",
            8 => "反无效通过",
            9 => "反无效驳回",
            10 => "反无效撤回",
            11 => "批量分单",
        ];
        return $status[$data['czaction']];
    }
    /**
     * 客户端获取器
     * @param $value
     * @param $data
     * @return mixed
     * @author: Huang
     */
    public function getKhdTextAttr($value, $data)
    {
        $status = [
            1 => "PC端操作",
            2 => "微信端操作"
        ];
        return $status[$data['khd']];
    }
    /**
     * 操作人获取器
     * @param $value
     * @param $data
     * @return mixed
     * @author: Huang
     */
    public function getCzryTextAttr($value, $data)
    {
        $status = Cache::tag('alluser')->get('userinfotext');
        if (empty($status)) {
            $getUserInfo = new User();
            $status = collect($getUserInfo->getAllUsers())->column('username','id');
            Cache::tag('alluser')->set('userinfotext', $status);
        }
        return $status[$data['czry']];
    }
    /**
     * 状态获取器
     * @param $value
     * @param $data
     * @return mixed
     * @author: Huang
     */
    public function getStateTextAttr($value, $data)
    {
        $status = \app\admin\logic\State::statesToText();
        return $status[$data['state']];
    }
    /**
     * 部门获取器
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getDeparIdTextAttr($value, $data)
    {
        $status = \app\admin\logic\Depar::deparsToText();
        return $status[$data['depar_id']];
    }
}	